<template>
  <div class="app-container">
    <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" label-width="88px">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="eidtAlgorithm">策略选择</el-button>
      </el-col>
    </wms-form>
    <wms-table :loading="loading" :data-list="algorithmList" :column="column" :pageInfo="queryParams"
      @get-list="getList" />
    <add-or-update v-if="showEdit" v-model="showEdit" @refresh="getList" />
  </div>
</template>

<script setup name="Spu">
import { listAlgorithm } from "@/api/wms/algorithm";
import WmsTable from '@/components/WmsTable/index.vue'
import WmsForm from '@/components/WmsForm/index.vue'
import AddOrUpdate from './components/algorithm-add-or-update.vue'
import { data, column, formList } from './index.js'
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);

const algorithmList = ref([]);
const loading = ref(true);
let showEdit = ref(false)

/** 查询物料列表 */
function getList() {
  loading.value = true;
  listAlgorithm(proxy.addDateRange(queryParams, queryParams.dateRange)).then(
    (response) => {
      algorithmList.value = response.rows;
      queryParams.total = response.total;
      loading.value = false;
    }
  );
}

function eidtAlgorithm(row) {
  console.log("选择策略算法：", row)
  showEdit.value = true;
}

// 表单重置
function reset() {
  form.value = {
    algorithmNo: null,
    algorithmName: null,
    algorithmType: null,
    algorithmInfo: null,
  };
  proxy.resetForm("algorithmRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  queryParams.dateRange = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

getList();
</script>
